import { Module } from 'vuex'

import { getdata } from '@/service/main/analysis/dashboard'

import { IDashboardState } from './types'
import { IRootState } from '../../type'

const dashboardModule: Module<IDashboardState, IRootState> = {
  namespaced: true,
  state() {
    return {
      vipList: [],
      appliList: [],
      leaveList: [],
      makeList: [],
      markList: []
    }
  },
  mutations: {
    changevipList(state, list) {
      state.vipList = list
    },
    changeappliList(state, list) {
      state.appliList = list
    },
    changeleaveList(state, list) {
      state.leaveList = list
    },
    changemakeList(state, list) {
      state.makeList = list
    },
    changemarkList(state, list) {
      state.markList = list
    }
  },
  actions: {
    async getDashboardDataAction({ commit }) {
      let Result = await getdata()
      let Date = JSON.parse(Result.data)
      console.log(JSON.parse(Result.data).VipData)
      commit('changevipList', Date.VipData)
      commit('changeappliList', Date.appliData)
      commit('changeleaveList', Date.leaveData)
      commit('changemakeList', Date.makeData)
      commit('changemarkList', Date.markData)
    }
  }
}

export default dashboardModule
